package View;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import Controller.ControladorUsuarios;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;

public class GestionarUsuario extends JFrame {

	private JPanel contentPane;
	private JTextField textFieldUs;
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GestionarUsuario frame = new GestionarUsuario();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public GestionarUsuario() {
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 11, 414, 240);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblUsuario = new JLabel("Usuario");
		lblUsuario.setBounds(88, 62, 46, 14);
		panel.add(lblUsuario);
		
		textFieldUs = new JTextField();
		textFieldUs.setBounds(156, 59, 149, 20);
		panel.add(textFieldUs);
		textFieldUs.setColumns(10);
		JLabel lblClave = new JLabel("Clave");
		lblClave.setBounds(88, 97, 46, 14);
		panel.add(lblClave);
		
		JButton btnAdd = new JButton("Iniciar");
		btnAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ControladorUsuarios controladorUsuarios = new ControladorUsuarios();
				if (controladorUsuarios.autenticar(textFieldUs.getText(), passwordField.getText())) {
					/*JOptionPane.showMessageDialog(null, "Yey");*/
					ProcesarElementosBasicos procesarElementosBasicos = new ProcesarElementosBasicos();
					procesarElementosBasicos.setVisible(true);
					
				} else {
					JOptionPane.showMessageDialog(null, "Usuario o clave incorrecta.");
				}
			}
		});
		btnAdd.setBounds(87, 151, 89, 23);
		panel.add(btnAdd);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			GestionarUsuario.this.dispose();
			}
		});
		btnCancelar.setBounds(216, 151, 89, 23);
		panel.add(btnCancelar);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(156, 94, 149, 20);
		panel.add(passwordField);
	}

	public JTextField getTextFieldUs() {
		return textFieldUs;
	}

	public void setTextFieldUs(JTextField textFieldUs) {
		this.textFieldUs = textFieldUs;
	}

	public JPasswordField getPasswordField() {
		return passwordField;
	}

	public void setPasswordField(JPasswordField passwordField) {
		this.passwordField = passwordField;
	}
	
	
}
